package com.whereistheparty;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class AddPartyActivity extends Activity
{
	 private  Spinner s_PartyType;  
	 public void onLoadFinished()
	 {
		 
		  final EditText e_PartyName = (EditText)findViewById(R.id.e_PartyName); 
			final EditText e_PartyDescription = (EditText)findViewById(R.id.e_PartyDescription);

			e_PartyName.setText(WhereisthepartyActivity.PartyName);
	    	e_PartyDescription.setText(WhereisthepartyActivity.PartyDescription);
		 
		   // mAdapter.swapCursor(data);
	}
	 
	 public void onCreate(Bundle savedInstanceState) 
	 {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.addparty);	 
	        
	        ArrayAdapter<Object> aa = new ArrayAdapter<Object>(this,android.R.layout.simple_spinner_item,WhereisthepartyActivity.PartyTypes);    
   	        
	        s_PartyType= (Spinner)findViewById(R.id.s_PartyType);   
	    	        
	        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);      
	        s_PartyType.setAdapter(aa);        
	        
	        
	        manageButtons();	        
	 }

	private void manageButtons()
	{
		 Button btnCancel = new Button(AddPartyActivity.this);
		 Button btnForward = new Button(AddPartyActivity.this);
		 
		 
		 btnCancel = (Button)findViewById(R.id.btnBack); 
		 btnForward = (Button)findViewById(R.id.btnForward); 
		 
		 btnCancel.setOnClickListener(new OnClickListener()
		 {			
			public void onClick(View v) 
			{
				
				Intent i = new Intent(getApplicationContext(),
						WhereisthepartyActivity.class);
				startActivity(i);
				finish();
			}
		});
		 btnForward.setOnClickListener(new OnClickListener()
		 {			
			public void onClick(View v) 
			{
				 final EditText e_PartyName = (EditText)findViewById(R.id.e_PartyName); 
				 final EditText e_PartyDescription = (EditText)findViewById(R.id.e_PartyDescription);

		        WhereisthepartyActivity.PartyName =  e_PartyName.getText().toString();
		        WhereisthepartyActivity.PartyDescription = e_PartyDescription.getText().toString(); 		            
		        WhereisthepartyActivity.PartyType = s_PartyType.getSelectedItem().toString(); 
		        if(e_PartyName.length()<30)
		        {
		        	if(e_PartyDescription.length()<70)
			        {
		        		if(!((e_PartyName.getText().toString().equals(""))||(e_PartyDescription.getText().toString().equals(""))))
			        	{
			        		Intent i = new Intent(getApplicationContext(),
							AddPartyActivity2.class);
			        		startActivity(i);
			        		finish();
			        	}
			        	else
			        	{
			        		Toast.makeText(AddPartyActivity.this, "Please fill necessary information", Toast.LENGTH_LONG)
	                        .show();
			        	}
			        }
		        	else
		        	{
		        		Toast.makeText(AddPartyActivity.this, "Party Description must be shorter than 70 characters ", Toast.LENGTH_LONG).show();
		 		       
		        	}
		        	
		        }
		        else
		        {
		        	Toast.makeText(AddPartyActivity.this, "Party Name must be shorter than 30 characters ", Toast.LENGTH_LONG).show();
		        }
		        	
		        }
			
		});
	}

}
